// 码农果果蔬
const express = require('express')
const apiRouter = express.Router()
const fs = require('fs')
const writeData = require('../../db/module/writeData')
const readData = require('../../db/module/readData')
const delData = require('../../db/module/delData')
const jwt = require('jsonwebtoken')
const { disposeDatabase } = require('../../models/relevanceDatabase')
const { default: axios } = require('axios')
const secretKey = 'Aa2317770710' //生成token的密钥
const crypto = require('crypto')
const decryptData = require('../../models/decryptData')

// 获取账单列表
apiRouter.post('/getConstructionSiteBill', async (req, res) => {
    try {
        const params = req.body
        let result = await readData(params, 'constructionSiteBill')
        res.send(result)
    } catch (error) {
        res.send({
            code: 50000,
            msg: error
        })
    }
})

// 删除账单列表
apiRouter.post('/delConstructionSiteBill', async (req, res) => {
    try {
        let result = await delData(req.body, 'constructionSiteBill')
        res.send(result)
    } catch (error) {
        res.send({
            code: 50000,
            msg: error
        })
    }
})

// 添加账单
apiRouter.post('/addConstructionSiteBill', async (req, res) => {
    try {
        const params = req.body
        let result = await writeData(params, 'constructionSiteBill')
        res.send(result)
    } catch (error) {
        res.send({
            code: 50000,
            msg: error
        })
    }
})

// 查看账单详情
apiRouter.post('/getConstructionSiteBillDetail', async (req, res) => {
    try {
        const params = req.body
        let result = await readData(params, 'constructionSiteBillDetail')
        res.send(result)
    } catch (error) {
        res.send({
            code: 50000,
            msg: error
        })
    }
})

// 删除账单详情
apiRouter.post('/deleteConstructionSiteBillDetail', async (req, res) => {
    try {
        const params = req.body
        let result = await delData(params, 'constructionSiteBillDetail')
        res.send(result)
    } catch (error) {
        res.send({
            code: 50000,
            msg: error
        })
    }
})

// 新增账单详情
apiRouter.post('/addConstructionSiteBillDetail', async (req, res) => {
    try {
        const params = req.body
        let result = await writeData(params, 'constructionSiteBillDetail')
        res.send(result)
    } catch (error) {
        res.send({
            code: 50000,
            msg: error
        })
    }
})

module.exports = apiRouter
